<?php
/**
 * @title 901. 股票价格跨度
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }


class StockSpanner {
    /**
     */
    function __construct() {
        /**
         * @since 2024-01-13 单调递减栈
         */
        $this->stack = [];
    }

    /**
     * @param Integer $price
     * @return Integer
     */
    function next($price) {
        /**
         * @since 2024-01-13 当日价格跨度
         */
        $priceCount = 1;

        /**
         * @since 2024-01-13 和栈顶元素比较
         */
        while(!empty($this->stack)){
            /**
             * @since 2024-01-13 栈顶元素
             */
            list($topPrice, $topCount) = end($this->stack);

            /**
             * @since 2024-01-13 比栈顶元素小
             */
            if($price < $topPrice){
                break;
            } else {
                /**
                 * @since 2024-01-13 元素出栈
                 */
                array_pop($this->stack);

                /**
                 * @since 2024-01-13 更新当日价格跨度
                 */
                $priceCount += $topCount;
            }
        }

        /**
         * @since 2024-01-13 元素入栈
         */
        $this->stack[] = [$price, $priceCount];

        /**
         * @since 2024-01-13 返回当日价格跨度
         * @return Integer
         */
        return $priceCount;
    }
}

/**
 * Your StockSpanner object will be instantiated and called as such:
 * $obj = StockSpanner();
 * $ret_1 = $obj->next($price);
 */

/**
 * @url http://127.0.0.1/leetcode/202401/2024.01.13_5.php
 */
$datas = [

];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    if(count($data) <= 20){
        var_dump($data);
    } else {
        var_dump(count($data));
    }

    $obj = new Solution();
    $result = $obj->(...$data);
    // $result = $obj->($xhprof->tree($data));
    // $result = $obj->($xhprof->listNode($data));
    // $result = $obj->find(...$data);
    var_dump($result);
    // if(count($result)<=20){
    //     var_dump($result);
    // } else {
    //     var_dump(count($result));
    // }
    echo str_repeat(PHP_EOL, 3);
    echo str_repeat("<br>", 3);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
